/* GUI CONVERTED from reutlrp.p (converter v1.76) Mon Aug 12 22:34:44 2002 */
/* reutlrp.p - Line Utilization Report                                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                    */
/* All rights reserved worldwide.  This is an unpublished work.           */
/* $Revision: 1.11.1.12 $                                                  */
/*V8:ConvertMode=FullGUIReport                                            */
/* REVISION: 7.0    LAST MODIFIED: 02/25/92     BY: smm *F230*            */
/* REVISION: 7.0    LAST MODIFIED: 04/06/92     BY: smm *F364*            */
/* REVISION: 7.3    LAST MODIFIED: 12/29/92     BY: emb *G467*            */
/* REVISION: 7.3    LAST MODIFIED: 01/08/93     BY: emb *G529*            */
/* REVISION: 7.3    LAST MODIFIED: 01/23/95     BY: cpp *F0CR*            */
/* REVISION: 7.3    LAST MODIFIED: 01/30/96     by: jym *G1LJ*            */
/* REVISION: 7.3    LAST MODIFIED: 07/29/96 BY: *G29Y* Julie Milligan     */
/* REVISION: 8.5    LAST MODIFIED: 05/08 97 BY: *J1QX* Julie Milligan     */
/* REVISION: 8.5    LAST MODIFIED: 08/25/97 BY: *H1DK* Todd Runkle        */
/* REVISION: 8.6    LAST MODIFIED: 10/16/97 BY: GYK         *K10W*        */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane          */
/* REVISION: 8.6E   LAST MODIFIED: 10/04/98 BY: *J314* Alfred Tan         */
/* REVISION: 9.1    LAST MODIFIED: 06/04/99 BY: *J3FH* Jyoti Thatte       */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00 BY: *N0KP* myb                */
/* REVISION: 9.1    LAST MODIFIED: 09/11/00 BY: *N0RQ* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                */
/* Revision: 1.11.1.6    BY: Rajiv Ramaiah  DATE: 04/23/02  ECO: *M1XY*   */
/* $Revision: 1.11.1.12 $  BY: Amit Chaturvedi DATE: 08/06/02  ECO: *N1P3*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

define variable line           like rps_line             no-undo.
define variable line1          like rps_line             no-undo.
define variable site           like rps_site             no-undo.
define variable site1          like rps_site             no-undo.
define variable due            like rps_due_date         no-undo.
define variable due1           like rps_due_date         no-undo.
define variable lnrate         like ln_rate              no-undo.
define variable old_part       like rps_part             no-undo.
define variable um             like pt_um                no-undo.
define variable changetime     like chg_time             no-undo.
define variable shift_amt      like seq_qty_req extent 4 no-undo.

define variable hours          as   decimal extent 4     no-undo.
define variable cap            as   decimal extent 4     no-undo.
define variable cap-ori        as   decimal extent 4     no-undo.

define variable i              as   integer              no-undo.
define variable total_load     as   decimal              no-undo.
define variable total_cap      as   decimal              no-undo.
define variable shopcal_recno  as   recid                no-undo.
define variable last_date      as   date                 no-undo.
define variable last_shift     as   integer              no-undo.
define variable first_time     as   logical initial true no-undo.
define variable l_productivity as   decimal extent 4     no-undo.
define variable l_change_load  as   decimal              no-undo.
define variable disp-wdays     as   character            no-undo.
define variable shift          as   character            no-undo.
define variable daylabel       as   character format "x(12)".
define variable capacity       as   decimal label "Capacity"
   format ">,>>9.9<"           no-undo.
define variable sh_hours       as   decimal label "Hours"
   format ">,>>9.9<"           no-undo.
define variable load           as   decimal label "Load"
   format ">,>>9.9<"           no-undo.
define variable util           as   decimal label "Utilization"
   format ">,>>9.9<%"          no-undo.
define variable err            as   character format "x(3)"
   initial "***"               no-undo.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
site     colon 20
   site1    colon 50 label {t001.i}
   line     colon 20
   line1    colon 50 label {t001.i}
   due      colon 20
   due1     colon 50 label {t001.i}
   skip
 SKIP(.4)  /*GUI*/
with frame a width 80 side-labels attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

assign
   disp-wdays = getTermLabel("SUNDAY",12) + ","
   + getTermLabel("MONDAY",12) + ","
   + getTermLabel("TUESDAY",12) + ","
   + getTermLabel("WEDNESDAY",12) + ","
   + getTermLabel("THURSDAY",12) + ","
   + getTermLabel("FRIDAY",12) + ","
   + getTermLabel("SATURDAY",12)
   site  = global_site
   site1 = global_site
   due   = today.

/* TO BUILD WEB PAGE SPEC AND WEB PAGE DATA */
{wbrp01.i}

/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

   if line1 = hi_char  then line1 = "".
   if site1 = hi_char  then site1 = "".
   if due   = low_date then due   = ?.
   if due1  = hi_date  then due1  = ?.

   if c-application-mode <> 'web'
   then
      
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update &fields = "  site site1 line
                   line1 due due1" &frm = "a"}

   if (c-application-mode <> 'web')
   or (c-application-mode = 'web'
       and (c-web-request begins 'data'))
   then do:

      bcdparm = "".
      {mfquoter.i  site}
      {mfquoter.i  site1}
      {mfquoter.i  line}
      {mfquoter.i  line1}
      {mfquoter.i  due }
      {mfquoter.i  due1}
   end. /* IF (c-application-mode <> 'web'...) */

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:




   /* ANALYSE PRINT HEADER */
   {mfphead.i}

   if site1 = "" then site1 = hi_char.
   if line1 = "" then line1 = hi_char.
   if due   = ?  then due   = low_date.
   if due1  = ?  then due1  = hi_date.

   for each ln_mstr
      fields(ln_line ln_rate ln_site)
      where (ln_site >= site
        and  ln_site <= site1)
        and (ln_line >= line
        and  ln_line <= line1)
      no-lock
      break
      by ln_site
      by ln_line
      with frame b:

      if first-of(ln_line)
      then
         first_time = true.

      for first shop_cal
         fields(shop_hours shop_site shop_wkctr shop_mch)
         where shop_site  = ln_site
         and   shop_wkctr = ln_line
         and   shop_mch   = ""
         no-lock:
      end. /* FOR FIRST shop_cal */

      if not available shop_cal
      then
         for first shop_cal
            fields(shop_hours shop_site shop_wkctr shop_mch)
            where shop_site  = ""
            and   shop_wkctr = ln_line
            and   shop_mch   = ""
            no-lock:
         end. /* FOR FIRST shop_cal */

      if not available shop_cal
      then
         for first shop_cal
            fields(shop_hours shop_site shop_wkctr shop_mch)
            where shop_site  = ln_site
            and   shop_wkctr = ""
            and   shop_mch   = ""
            no-lock:
         end. /* FOR FIRST shop_cal */

      if not available shop_cal
      then
         for first shop_cal
            fields(shop_hours shop_site shop_wkctr shop_mch)
            where shop_site  = ""
            and   shop_wkctr = ""
            and   shop_mch   = ""
            no-lock:
         end. /* FOR FIRST shop_cal */

      if available shop_cal
      then
         shopcal_recno = recid(shop_cal).
      else
         shopcal_recno = 0.

      assign
         last_date  = due - 1
         last_shift = 0
         total_load = 0
         total_cap  = 0
         changetime = 0
         cap        = 0
         old_part   = ""
         hours      = 0.

      if due = low_date
      then
         for first seq_mstr
            fields(seq_due_date seq_line   seq_part   seq_qty_req seq_priority
                   seq_shift2   seq_shift3 seq_shift4 seq_site)
            where seq_site = ln_site
            and   seq_line = ln_line
            use-index seq_sequence
            no-lock:
         end. /* FOR FIRST seq_mstr */
      else
         for first seq_mstr
            fields(seq_due_date seq_line   seq_part   seq_qty_req seq_priority
                   seq_shift2   seq_shift3 seq_shift4 seq_site)
            where seq_site     = ln_site
            and   seq_line     = ln_line
            and   seq_due_date >= due
            use-index seq_sequence
            no-lock:
         end. /* FOR FIRST seq_mstr */

      if available seq_mstr
      then do with frame b:

         last_date = seq_due_date.
         display
            ln_site @ seq_site
            ln_line @ seq_line
            last_date @ seq_due_date
            entry(weekday(last_date), disp-wdays) @ daylabel WITH STREAM-IO /*GUI*/ .
      end. /* IF AVAILABLE seq_mstr */

      repeat while available seq_mstr
      with frame b:

         FORM /*GUI*/ 
            seq_site
            seq_line     column-label "Prod Line"
            seq_due_date column-label "Due Date"
            daylabel no-label
            shift
            sh_hours
            capacity
            seq_part     column-label "Item Number"
            rps_qty_req
            um
            load
            util
            err no-label
         with STREAM-IO /*GUI*/  frame b down width 132.

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame b:handle).

         if seq_due_date > due1
         then
            leave.

         /* FOR FIRST RECORD THRU SET UP INITIAL VALUES FOR CAPACITY, HOURS */
         if first_time
         then do:

            first_time = false.
            {reutlcap.i &date=last_date}
            do i = 1 to 4:
               assign
                  cap[i]     = max(cap[i],0)
                  cap-ori[i] = max(cap[i],0)
                  hours[i]   = max(hours[i],0).
            end. /* DO i = 1 TO 4 */
         end. /* IF first_time */

         if page-size - line-counter < 3
         then do:

            page.
            display
               seq_site
               seq_line WITH STREAM-IO /*GUI*/ .
            old_part = "".
         end. /* IF page-size - line-counter < 3 */

         /* CHECK FOR CHANGE IN ITEM/PART - GET CHANGE-OVER TIME */
         if old_part <> seq_part
         then do:

            if old_part <> ""
            then do:

               changetime = 0.
               for first chg_mstr
                  fields(chg_from chg_line chg_site chg_time chg_to)
                  where chg_site = seq_site
                  and   chg_line = seq_line
                  and   chg_from = old_part
                  and   chg_to   = seq_part
                  no-lock:
               end. /* FOR FIRST chg_mstr */

               if not available chg_mstr
               then do:

                  for first chg_mstr
                     fields(chg_from chg_line chg_site chg_time chg_to)
                     where chg_site = seq_site
                     and   chg_line = seq_line
                     and   chg_from = ""
                     and   chg_to   = seq_part
                     no-lock:
                  end. /* FOR FIRST chg_mstr */
               end. /* IF NOT AVAILABLE chg_mstr */

               if available chg_mstr
               then
                  changetime = chg_time.
            end. /* IF old_part <> "" */

            assign
               old_part = seq_part
                     um = "".
            for first pt_mstr
               fields(pt_part pt_um)
               where pt_part = seq_part
               no-lock:

               um = pt_um.
            end. /* FOR FIRST pt_mstr */
         end.  /* OLD_PART <> SEQ_PART */

         /* SET LINE RATE (UNITS/HR) FROM LN_MSTR FILE, YOU WILL OVERLAY     */
         /* LATER IF LN_DET EXISTS.  SET SHIFT AMT (QTY) FROM SEQ_MSTR       */
         /* AS DECIMAL, THEREFORE TO RETAIN ANY DECIMAL VALUE ENTERED BY THE */
         /* THE USER, THE shift_amt[1] MUST BE CALCULATED.                   */
         assign
            lnrate       = ln_rate
            shift_amt[1] = seq_qty_req - seq_shift2 - seq_shift3 - seq_shift4
            shift_amt[2] = seq_shift2
            shift_amt[3] = seq_shift3
            shift_amt[4] = seq_shift4.

         for last lnd_det
            fields(lnd_line lnd_part lnd_rate lnd_site lnd_start)
            where lnd_line  = seq_line
            and   lnd_site  = seq_site
            and   lnd_part  = seq_part
            and   lnd_start <= seq_due_date
            no-lock:
         end. /* FOR LAST lnd_det */

         if  available lnd_det
         and lnd_rate <> 0
         then
            lnrate = lnd_rate.

         /* WHEN DAY CHANGES ACCUMULATE TOTAL CAPACITY FOR TOTAL LINE */
         do while last_date <> seq_due_date
         with frame b:

            if (hours[1] > 0
            or  hours[2] > 0
            or  hours[3] > 0
            or  hours[4] > 0)
            then do with frame b:

               do i = max(last_shift,1) to 4:

                  if last_shift <> i
                  then do:

                     total_cap = total_cap + cap[i].

                     if page-size - line-counter < 3
                     then do with frame b:

                        page.
                        display
                           seq_site
                           seq_line
                           last_date @ seq_due_date
                           entry(weekday(last_date), disp-wdays) @ daylabel
                           getTermLabel("CONT",8) @ shift
                        with frame b STREAM-IO /*GUI*/ .

                        if hours[1] > 0
                        then
                           down 1 with frame b.
                     end. /* IF page-size - line-counter < 3 */

                     if hours[i] > 0
                     then
                        display
                           getTermLabel("SHIFT",5) + " " + string(i)
                           @ shift no-label
                           hours[i] @ sh_hours
                           cap[i] @ capacity WITH STREAM-IO /*GUI*/ .
                     last_shift = i.
                  end.  /* LAST SHIFT <> i */

                  /* CHECK FOR CHANGE-OVER FROM ONE ITEM TO THE NEXT ITEM */
                  if changetime > 0
                  then do:

                     if hours[i] > changetime
                     then do:

                        /* CALCULATED CHANGETIME LOAD AS  */
                        /* CHANGETIME * PRODUCTIVITY      */
                        l_change_load = changetime * l_productivity[i].

                        display
                           getTermLabel("CHANGE-OVER_****",18) @ seq_part
                           l_change_load @ load
                           l_change_load / cap-ori[i] * 100
                           when (cap-ori[i] > 0) @ util
                        with frame b STREAM-IO /*GUI*/ .
                        down 1 with frame b.
                        assign
                           total_load = total_load + l_change_load
                           cap[i]     = cap[i] * (1 - changetime / hours[i])
                           hours[i]   = hours[i] - changetime
                           changetime = 0.
                     end. /* IF hours[i] > changetime */

                     /* IF HOURS ARE > ZERO BUT ARE VERY SMALL (IE, < .05)   */
                     /* THEN DON'T USE. ONLY USE HOURS THAT WHEN ROUNDED WILL*/
                     /* SHOW UP ON THE REPORT.  TO SHOW ZERO HOURS AS        */
                     /* CHANGE-OVER WILL BE CONFUSING                        */
                     else do:

                        /* ALLOWS FOR SMALLER AMOUNTS OF HOUR */
                        /* TO BE DISPLAYED                    */
                        if round (hours[i],2) > .05
                        then do with frame b:

                           /* CALCULATED CHANGETIME LOAD AS */
                           /* CHANGETIME * PRODUCTIVITY     */
                           l_change_load =  (hours[i] * l_productivity[i]).

                           display
                              getTermLabel("CHANGE-OVER_****",18) @ seq_part
                              l_change_load @ load
                              (l_change_load / cap-ori[i]) * 100
                              when (cap-ori[i] > 0) @ util
                           with frame b STREAM-IO /*GUI*/ .
                           down 1 with frame b.
                           total_load = total_load + l_change_load.
                        end. /* IF ROUND (hours[i],0) > .0 */

                        assign
                           changetime        = changetime - hours[i]
                           hours[i]          = 0
                           cap[i]            = 0
                           l_productivity[i] = 1.
                     end. /* hours > changetime */
                  end. /* IF changetime > 0 */
               end. /* DO i = max(last_shift,1) TO 4 */
            end. /* DO hours 1-4 > 0 */

            /* PUT OUT TOTAL LINE */
            if total_cap > 0
            or total_load > 0
            then do:

               underline capacity load util with frame b.
               display
                  total_cap @ capacity
                  total_load @ load
                  total_load * 100 / total_cap when (total_cap > 0) @ util
                  err when (total_cap <= 0 or total_load <= 0)
               with frame b STREAM-IO /*GUI*/ .
               if page-size - line-counter > 4
               then
                  down 2 with frame b.
            end. /* IF total_cap > 0 OR total_load > 0 */

            /* TOTAL LINE PRINTED, NOW BEGIN NEXT DAY */
            for first shop_cal
               fields(shop_hours shop_mch shop_site shop_wkctr)
               where recid(shop_cal) = shopcal_recno
               no-lock:
            end. /* FOR FIRST shop_cal */

            last_date = last_date + 1.

            /* CALL reutlcap.i TO SET UP CAPACITY AND HOURS BY SHIFT.  */
            /* reutlcap.i USES SHFT_DET TO CALCULATE THE INITIAL HOURS */
            /* AND CAPACITY THEN IF CAL_DETAIL RECORDS EXIST ADDS      */
            /* ADDITIONAL HOURS AND CAPACITY                           */

            {reutlcap.i &date=last_date}

            do i = 1 to 4:
               assign
                  cap[i]   = max(cap[i],0)
                  hours[i] = max(hours[i],0).
            end. /* DO i = 1 TO 4 */

            /* INITIALIZE COUNTERS / VARIABLES FOR NEW DAY */
            assign
               total_load = 0
               total_cap  = 0
               last_shift = 0
               cap-ori[1] = cap[1]
               cap-ori[2] = cap[2]
               cap-ori[3] = cap[3]
               cap-ori[4] = cap[4].

            if hours[1]  > 0
            or hours[2]  > 0
            or hours[3]  > 0
            or hours[4]  > 0
            or last_date = seq_due_date
            then do:

               if page-size - line-counter < 5
               then do with frame b:

                  page.
                  display
                     seq_site
                     seq_line
                  with frame b STREAM-IO /*GUI*/ .
               end. /* IF page-size - line-counter < 5 */

               display
                  last_date @ seq_due_date
                  entry(weekday(last_date), disp-wdays) @ daylabel
               with frame b STREAM-IO /*GUI*/ .
            end. /* IF hours 1-4 > 0 */
         end. /* TOT cap > 0 OR TOT LOAD > 0 */

         /* CHECK EACH SHIFT AND PRINT DETAIL LINE - ALSO CK FOR CHG-OVER */
         do i = 1 to 4 with frame b:

            if shift_amt[i] > 0
            or (changetime  > 0
            and hours[i]    > 0)
            then do with frame b:

               if page-size - line-counter < 5
               then do with frame b:

                  page.
                  display
                     seq_site
                     seq_line
                     seq_due_date
                     entry(weekday(seq_due_date), disp-wdays) @ daylabel
                     getTermLabel("CONT",8) @ shift
                  with frame b STREAM-IO /*GUI*/ .

                  if last_shift <> i
                  then
                     down 1 with frame b.
               end. /* IF page-size - line-counter < 5 */
               /* ELIMINATES REDUNDANT DISPLAY AND ACCUM OF CAPACITY */
               if last_shift < i
               then do:

                  total_cap = total_cap + cap[i].

                  display
                     getTermLabel("SHIFT",5) + " " + string(i) @ shift no-label
                     hours[i] @ sh_hours
                     cap[i] @ capacity WITH STREAM-IO /*GUI*/ .
                  last_shift = i.
               end. /* IF last_shift <> i */

               /* CHECK FOR CHANGE-OVER FROM ONE ITEM/PART TO ANOTHER */
               if changetime > 0
               then do with frame b:

                  if hours[i] > changetime
                  then do:

                     /* BEGIN ADD SECTION CALCULATED CHANGETIME LOAD */
                     /* AS CHANGETIME * PRODUCTIVITY                 */
                     l_change_load = changetime * l_productivity[i].

                     display
                        getTermLabel("CHANGE-OVER_****",18) @ seq_part
                        l_change_load @ load
                        (l_change_load / cap-ori[i]) * 100
                        when (cap-ori[i] > 0) @ util
                     with frame b STREAM-IO /*GUI*/ .
                     down 1 with frame b.
                     assign
                        total_load = total_load + l_change_load
                        cap[i]     = cap[i] * (1 - changetime / hours[i])
                        cap[i]     = round(cap[i],2)
                        hours[i]   = hours[i] - changetime
                        hours[i]   = round(hours[i],2)
                        changetime = 0.
                  end. /* IF hours[i] > changetime */

                  /* IF HOURS ARE > ZERO BUT ARE VERY SMALL (IE, < .05) THEN */
                  /* DON'T USE. ONLY USE HOURS THAT WHEN ROUNDED WILL SHOW UP*/
                  /* ON THE REPORT. T O SHOW ZERO HOURS AS CHANGE-OVER WILL  */
                  /* BE CONFUSING                                            */
                  else do:

                     /* ALLOWS FOR SMALLER AMOUNTS OF HOUR */
                     /* TO BE DISPLAYED                    */
                     if round (hours[i],2) > .05
                     or shift_amt[i]       > 0
                     then do with frame b:

                        /* CALCULATED CHANGETIME LOAD AS  */
                        /* CHANGETIME * PRODUCTIVITY      */

                        l_change_load = hours[i] * l_productivity[i].

                        display
                           getTermLabel("CHANGE-OVER_****",18) @ seq_part
                           l_change_load @ load
                           (l_change_load / cap-ori[i]) * 100
                           when (cap-ori[i] > 0) @ util
                        with frame b STREAM-IO /*GUI*/ .

                        total_load = total_load + l_change_load.

                        if shift_amt[i] > 0
                        then
                           display
                              l_change_load @ load
                        with frame b STREAM-IO /*GUI*/ .
                        down 1 with frame b.
                     end. /* IF ROUND (hours[i],0) > .0 */

                     changetime = changetime - hours[i].

                     if shift_amt[i] > 0
                     then
                        changetime = 0.

                     assign
                        hours[i]          = 0
                        cap[i]            = 0
                        l_productivity[i] = 1.
                  end.  /* ELSE DO , IF hours[i] > changetime */
               end.  /* IF changetime > 0 */

               /* CALCULATE LOAD AND UTILIZATION FOR DETAIL PRINT LINE */
               if shift_amt[i] > 0
               then do with frame b:

                  load = 0.

                  if lnrate > 0
                  then
                     load = shift_amt[i] / lnrate.

                  util = 0.

                  if cap-ori[i] > 0
                  then
                     util = load * 100 / cap-ori[i].

                  /* REPLACED THE EXISTING LOGIC FOR CALCULATION   */
                  /* OF REMAINING HRS BY (CAPACITY / PRODUCTIVITY).*/
                  /* EARLIER IT WAS CALCULATED AS HRS - LOAD       */

                  assign
                     cap[i]     = max(cap[i] - load,0)
                     hours[i]   = cap[i] / l_productivity[i]
                     total_load = total_load + load.

                  /* PRINT THE DETAIL LINE */
                  display
                     seq_part
                     shift_amt[i] @ rps_qty_req
                     um
                     load
                     util
                     err when (load <= 0
                           or  util <= 0)
                  with frame b STREAM-IO /*GUI*/ .

                  down 1 with frame b.
               end. /* IF shift_amt > 0 */
            end. /* DO - SHIFTS, CHANGETIME, HOURS */
         end. /* DO SHIFTS 1 TO 4 */

         
/*GUI*/ {mfguirex.i  "false"} /*Replace mfrpexit*/


         /* READ NEXT SEQ_MSTR */
         find next seq_mstr no-lock
            where seq_site = ln_site
            and   seq_line = ln_line
         use-index seq_sequence no-error.
      end. /* REPEAT seq_mstr */

      /* PRINT TOTAL LINE */
      if total_cap > 0
      or total_load > 0
      then do with frame b:

         underline capacity load util with frame b.
         display
            total_cap @ capacity
            total_load @ load
            total_load * 100 / total_cap when (total_cap > 0) @ util
            err when (total_cap  <= 0
                  or  total_load <= 0)
         with frame b STREAM-IO /*GUI*/ .
         down 1 with frame b.
      end. /* IF total_cap > OR total_load > 0 */

      /* REPORT EXIT */
      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


   end. /* FOR EACH ln_mstr (PRODUCTION LINE) */

   /* REPORT TRAILER */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


end. /* REPEAT */

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" site site1 line line1 due due1 "} /*Drive the Report*/
